<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-table/css/bootstrap-table.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-switch/css/bootstrap-switch.min.css" />
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row">
			<div class="col-sm-12">
				<table id="table">
					<thead style="background-color: #00C0EF">
						<tr style="background-color: #00C0EF">
							<th class="text-center" data-field="building">楼栋-单元-门牌</th>
							<th class="text-center" data-field="livingPerson">现居人姓名</th>
							<th class="text-center" data-field="livingIdCard">现居人身份证</th>
							<th class="text-center" data-field="livingTel">现居人联系方式</th>
							<th class="text-center" data-field="propertyRight">产权</th>
							<th class="text-center" data-field="type">房屋类型</th>
							<th class="text-center" data-field="createTime">创建时间</th>
							<th class="text-center" data-field="id">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</section>
	<!-- Large modal -->
	<div id="modal" class="modal fade" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">房产管理</h4>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="building" class="control-label">楼栋：</label> <input type="text" class="form-control" id="building">
					</div>
					<div class="form-group">
						<label for="unit" class="control-label">单元：</label> <input type="text" class="form-control" id="unit">
					</div>
					<div class="form-group">
						<label for="doorCard" class="control-label">门牌：</label> <input type="text" class="form-control" id="doorCard">
					</div>
					<div class="form-group">
						<label for="propertyRight" class="control-label">产权：</label> <select class="form-control" id="propertyRight">
							<option value="">请选择...</option>
							<option value="小产型房">小产型房</option>
							<option value="两证房">两证房</option>
						</select>
					</div>
					<div class="form-group">
						<label for="propertyHolder" class="control-label">产权人姓名：</label> <input type="text" class="form-control" id="propertyHolder">
					</div>
					<div class="form-group">
						<label for="propertyIdCard" class="control-label">产权人身份证：</label> <input type="text" class="form-control" id="propertyIdCard">
					</div>
					<div class="form-group">
						<label for="propertyTel" class="control-label">产权人联系方式：</label> <input type="text" class="form-control" id="propertyTel">
					</div>
					<div class="form-group">
						<label for="livingPerson" class="control-label">现居人姓名：</label> <input type="text" class="form-control" id="livingPerson">
					</div>
					<div class="form-group">
						<label for="livingIdCard" class="control-label">现居人身份证：</label> <input type="text" class="form-control" id="livingIdCard">
					</div>
					<div class="form-group">
						<label for="livingTel" class="control-label">现居人联系方式：</label> <input type="text" class="form-control" id="livingTel">
					</div>
					<div class="form-group">
						<label for="subordinateUnits" class="control-label">所属单位：</label> <input type="text" class="form-control" id="subordinateUnits">
					</div>
					<div class="form-group">
						<label for="lowerHairUnit" class="control-label">下发单位：</label> <input type="text" class="form-control" id="lowerHairUnit">
					</div>
					<div class="form-group">
						<label for="type" class="control-label">房屋类型：</label><select class="form-control" id="type">
							<option value="">请选择...</option>
							<option value="自用">自用</option>
							<option value="租赁">租赁</option>
						</select>
					</div>
					<div class="form-group">
						<label for="remark" class="control-label">备注：</label> <input type="text" class="form-control" id="remark">
					</div>
				</div>
				<div class="modal-footer">
					<button id="submitBtn" type="button" class="btn btn-primary" onclick="insertProperty();">提交</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-export.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/tableExport.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-toolbar.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-filter-control.js"></script>
<script src="${pageContext.request.contextPath}/js/ajaxfileupload.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script>
	var selectId = '';
	function actionFormatter(value, row, index) {
		return [ "<button class='btn btn-success btn-xs glyphicon glyphicon-file' onclick='showModal(\"" + row.id + "\");'>查看详情</button>",
				"&nbsp;<button class='btn btn-danger btn-xs glyphicon glyphicon-trash' onclick='delProperty(\"" + row.id + "\")'>删除信息</button>", ].join('');
	}

	var table_dataset = [ {
		align : 'center',
		formatter : function strFormatter(value, row, index) {
			return row.building + "-" + row.unit + "-" + row.doorCard;
		}
	}, {
		field : 'livingPerson',
		align : 'center',
	}, {
		field : 'livingIdCard',
		align : 'center',
	}, {
		field : 'livingTel',
		align : 'center',
	}, {
		field : 'propertyRight',
		align : 'center',
	}, {
		field : 'type',
		align : 'center',
	}, {
		field : 'createTime',
		align : 'center',
		formatter : function timeFormatter(value, row, index) {
			return (new Date(row.createTime)).Format("yyyy-MM-dd hh:mm:ss");
		}
	}, {
		align : 'center',
		width : 300,
		formatter : actionFormatter,
	} ];
	$('#table').bootstrapTable(
			{
				url : "${pageContext.request.contextPath}/selectPropertys",
				idField : "sid",
				columns : table_dataset,
				striped : true, //是否显示行间隔色
				pagination : true, //是否显示分页
				pageSize : 10, //每页的记录行数
				pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数
				search : false, //是否显示搜索
				showRefresh : true,
				sidePagination : "server", //表示服务端请求  
				queryParamsType : "limit",
				queryParams : function queryParams(params) { //设置查询参数  
					var param = {
						offset : params.offset,
						limit : params.limit,
						building : $("#building1").val(),
						unit : $("#unit1").val(),
						doorCard : $("#doorCard1").val()
					};
					return param;
				},
				toolbar : "<button class='btn btn-primary glyphicon glyphicon-plus' onclick='showModal(\"" + '' + "\");'>新增数据</button>"
						+ "<div class='input-group' style='width:250px;float:right;margin-top:2px;margin-left:20px;'>"
						+ "<input type='text' class='form-control' placeholder='请输入门牌进行查询...' id='doorCard1' name='doorCard1'>"
						+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='querry();'>查询</button></span></div>"
						+ "<div class='input-group' style='width:250px;float:right;margin-top:2px;margin-left:20px;'>"
						+ "<input type='text' class='form-control' placeholder='请输入单元进行查询...' id='unit1' name='unit1'>"
						+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='querry();'>查询</button></span></div>"
						+ "<div class='input-group' style='width:250px;float:right;margin-top:2px;margin-left:20px;'>"
						+ "<input type='text' class='form-control' placeholder='请输入楼栋进行查询...' id='building1' name='building1'>"
						+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='querry();'>查询</button></span></div>",
				icons : {
					paginationSwitchDown : 'glyphicon-collapse-down icon-chevron-down',
					paginationSwitchUp : 'glyphicon-collapse-up icon-chevron-up',
					refresh : 'glyphicon-refresh icon-refresh',
					toggle : 'glyphicon-list-alt icon-list-alt',
					columns : 'glyphicon-th icon-th',
					detailOpen : 'glyphicon-plus icon-plus',
					detailClose : 'glyphicon-minus icon-minus',
					"export" : 'glyphicon-export icon-share'
				},
				showExport : true,
				exportDataType : 'basic',
				exportTypes : [ 'json', 'xml', 'csv', 'txt', 'sql', 'excel' ],
			});

	function showModal(id) {
		selectId = id;
		if (id == '') {
			$("#building").val('');
			$("#unit").val('');
			$("#doorCard").val('');
			$("#propertyRight").val('');
			$("#propertyHolder").val('');
			$("#propertyIdCard").val('');
			$("#propertyTel").val('');
			$("#livingPerson").val('');
			$("#livingIdCard").val('');
			$("#livingTel").val('');
			$("#subordinateUnits").val('');
			$("#lowerHairUnit").val('');
			$("#type").val('');
			$("#remark").val('');
		} else {
			$.ajax({
				url : "${pageContext.request.contextPath}/selectPropertyById",
				type : "post",
				data : {
					id : id
				},
				dataType : "json",
				success : function(map) {
					var property = map['property'];
					$("#building").val(property.building);
					$("#unit").val(property.unit);
					$("#doorCard").val(property.doorCard);
					$("#propertyRight").val(property.propertyRight);
					$("#propertyHolder").val(property.propertyHolder);
					$("#propertyIdCard").val(property.propertyIdCard);
					$("#propertyTel").val(property.propertyTel);
					$("#livingPerson").val(property.livingPerson);
					$("#livingIdCard").val(property.livingIdCard);
					$("#livingTel").val(property.livingTel);
					$("#subordinateUnits").val(property.subordinateUnits);
					$("#lowerHairUnit").val(property.lowerHairUnit);
					$("#type").val(property.type);
					$("#remark").val(property.remark);
				}
			});
		}
		$('#modal').modal({
			backdrop : 'static',
			keyboard : false
		});
	}

	function insertProperty() {
		$("#submitBtn").button('loading');
		var building = $("#building").val();
		var unit = $("#unit").val();
		var doorCard = $("#doorCard").val();
		var propertyRight = $("#propertyRight").val();
		var propertyHolder = $("#propertyHolder").val();
		var propertyIdCard = $("#propertyIdCard").val();
		var propertyTel = $("#propertyTel").val();
		var livingPerson = $("#livingPerson").val();
		var livingIdCard = $("#livingIdCard").val();
		var livingTel = $("#livingTel").val();
		var subordinateUnits = $("#subordinateUnits").val();
		var lowerHairUnit = $("#lowerHairUnit").val();
		var type = $("#type").val();
		var remark = $("#remark").val();
		if (building === '' || unit === '' || doorCard === '') {
			layer.alert("请填写楼栋，单元，门牌!");
			$("#submitBtn").button('reset');
			return;
		}
		$.ajax({
			url : "${pageContext.request.contextPath}/insertAndUpdateProperty",
			type : "post",
			data : {
				id : selectId,
				building : building,
				unit : unit,
				doorCard : doorCard,
				propertyRight : propertyRight,
				propertyHolder : propertyHolder,
				propertyIdCard : propertyIdCard,
				propertyTel : propertyTel,
				livingPerson : livingPerson,
				livingIdCard : livingIdCard,
				livingTel : livingTel,
				subordinateUnits : subordinateUnits,
				lowerHairUnit : lowerHairUnit,
				type : type,
				remark : remark
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						$("#table").bootstrapTable('refresh');
						$("#modal").modal("hide");
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
				$("#submitBtn").button('reset');
			}
		});
	}

	function delProperty(id) {
		layer.confirm("是否删除此项？", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/insertAndUpdateProperty",
				type : "post",
				data : {
					id : id,
					status : '-1'
				},
				dataType : "json",
				success : function(data) {
					if (data.result === 1) {
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
						setTimeout(function() {
							$("#table").bootstrapTable('refresh');
						}, 500);
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function querry() {
		$("#table").bootstrapTable('refresh');
	}
</script>
</html>
